package com.yeban.base.day06;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/9/30
 */

import java.util.Scanner;

/**
 分析以下需求，并用代码实现
 有一分数序列：2/1，3/2，5/3，8/5，13/8，21/13... 定义一个方法求出这个数列的前20 项之和。
 */
public class StringText04 {

    // 输入第一项和第二项，返回对应的数组
    public static int[] addNumbersGroup(int n,int first, int second) {

        int next = first + second;
        int[] numberGrooups = new int[n];

        numberGrooups[0] = first;
        numberGrooups[1] = next;
        numberGrooups[2] = second;

        for (int i = 3; i < n; i++) {
            first = second;
            second = next;
            next = first + second;
            numberGrooups[i] = next;
        }

        return numberGrooups;
    }

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.print("请输入展示的数列长度n：");
        int n = sc.nextInt();

        // 分母
        int[] Up = addNumbersGroup(n,2,3);
        // 分子
        int[] Low = addNumbersGroup(n,1,2);

        System.out.print("分数数列为：");
        for (int i = 0; i < n - 1; i++) {
            System.out.print(Up[i] + "/" + Low[i] + ", ");
        }
        System.out.print(Up[n - 1] + "/" + Low[n - 1] + "...");

    }
}
